/**
* js class function  
* @param {object |date} today
* @param {object|date} party day of the event
* @param {string|date} id some identification string for the html elements
* @param {string} text to replace htmlcontent when reached to date
* @return {string} json date object
*/
webCountdown = function (today,party,id,text){
    
    // check and assing date objects  
    if (!today.getDay) today = new Date(today['year'],today['month'],today['day'],today['hour'],today['min'],today['sec']).getTime();
    if (!party.getDay) party = new Date(party['year'],party['month'],party['day'],party['hour'],party['min'],party['sec']).getTime();
    
    var curTime = party-today;
    var oldDay = false;
    var dayEl, timeEl;

    dayEl=document.getElementById('countDownClockDays'+id); 
    timeEl=document.getElementById('countDownClockTime'+id);
   
    // correct starting display
    if (curTime > 0) document.getElementById('countDownFullText'+id).style['visibility'] = 'visible';   

    return {
	// function called every time interval (second)
	actualize: function() { 
	    curTime -= 1000;
	    
	    // reach to date and remove time interval
	    if (curTime <=0) {
	       window.clearInterval(this.interval);
	       document.getElementById('countDownFullText'+id).innerHTML = text;
	       document.getElementById('countDownFullText'+id).style['visibility'] = 'visible';   
	       return;
	    }
	    
	    var curDay = Math.floor(curTime/(1000*60*60*24));
	    var curHour = Math.floor((curTime - curDay*(1000*60*60*24))/(1000*60*60));
	    var curMin = Math.floor((curTime - curHour*(1000*60*60) - curDay*(1000*60*60*24))/(1000*60));
	    var curSec = Math.floor((curTime - curMin*(1000*60) - curHour*(1000*60*60) - curDay*(1000*60*60*24))/(1000));
	    if (oldDay!=curDay) dayEl.innerHTML = curDay;
	    timeEl.innerHTML = curHour + ' h. ' + curMin+ ' m. ' + curSec + ' s.';
	    oldDay = curDay;
	},
	interval:false,
    }
}
